<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Auth
 * @subpackage Adapter
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Digest.php 23775 2011-03-01 17:25:24Z ralph $
 */


/**
 * @see Zend_Auth_Adapter_Interface
 */
require_once 'Ext/User/Action/Gain/Abstract.php';

/**
 * @category   Zend
 * @package    Zend_Auth
 * @subpackage Adapter
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Ext_User_Action_Gain_Adapter_Db extends Ext_User_Action_Gain_Abstract
{
    public function gain()
    {
        $_appModelDbTableUser = App_Model_DbTable_User::getInstance();
        $_userRow = $_appModelDbTableUser->getRowById($this->_userId);
        if(!$_userRow)
        {
            $_result = $this->setResult(Ext_User_Action_Gain_Result::FAILURE_RECORD_NOT_FONUD);
            return $_result;
        }
        
        $_settings = Zend_Registry::get('settings');
        if($_settings['userAccountUsername'])
        {
            $_appModelDbTableUserAccountBaseUsername = App_Model_DbTable_User_Account_Base_Username::getInstance();
			$_userAccountBaseUsernameRow = $_appModelDbTableUserAccountBaseUsername->getRowByUserId($this->_userId);
			if(isset($_userAccountBaseUsernameRow['username']))
			{
			    $_userRow['username'] = $_userAccountBaseUsernameRow['username'];
			}
        }
            
        $_appModelDbTableUserAccountBaseEmail = App_Model_DbTable_User_Account_Base_Email::getInstance();
        $_userAccountBaseEmailRow = $_appModelDbTableUserAccountBaseEmail->getRowByUserId($this->_userId);
        if(isset($_userAccountBaseEmailRow['email']))
    	{
    	    $_userRow['email'] = $_userAccountBaseEmailRow['email'];
    	}
        
    	$_result = $this->setResult(Ext_User_Action_Gain_Result::SUCCESS, $_userRow);
        return $_result;
    }

}
